 <!doctype html>
 <html lang="zh-CN">
 <head>
   <meta charset="UTF-8">
   <link rel="stylesheet" href="__PUBLIC__/Css/Admin/common.css">
   <link rel="stylesheet" href="__PUBLIC__/Css/Admin/main.css">
   <link rel="stylesheet" type="text/css" href="__PUBLIC__/Css/Admin/citylist.css"  />
   <script type="text/javascript" src="__PUBLIC__/Js/Admin/jquery.min.js"></script>
   <script type="text/javascript" src="__PUBLIC__/Js/Admin/colResizable-1.3.min.js"></script>
   <script type="text/javascript" src="__PUBLIC__/Js/Admin/common.js"></script>
   <script type="text/javascript" src="__PUBLIC__/js/Admin/city.js"></script>
   
   <script type="text/javascript">
      $(function(){
        $(".list_table").colResizable({
          liveDrag:true,
          gripInnerHtml:"<div class='grip'></div>", 
          draggingClass:"dragging", 
          minWidth:30
        }); 
        
        // 添加
        $("#btn_add").click(function(){
        	var province = new Province();
            var cities = province.getAllCities();
        	addCities(cities);
        });
        
        // 删除
        deleteById("__URL__/deleteCity");
        
        // 保存要添加的城市
        $("#btn_add_addCity").click(function(){
        	var cityName = "";
        	$("input[type='checkbox']:checked + label").each(function(){
        		if (cityName == "") {
        			cityName = $(this).text();
        		} else {
        			cityName += "," + $(this).text();
        		}
        		
        	});
        	var url = "__URL__/saveCity";
        	$("input[name='cityName']").val(cityName);
        	if($.trim(cityName) == ""){
        		alert("请选择要添加的城市");
        		return false;
        	}
        	$("#add_cities_form").attr("action", url);
        	$("#add_cities_form").submit();
        });

        
        // 返回
        $("#btn_rtn_addCity").click(function(){
        	$("#add_cities").hide();
        });
        
        // 全选城市
        $("#btn_checkAll_addCity").click(function(){
        	$("#cities_Ul input[type='checkbox']").each(function(){
        		$(this).attr("checked", true);
        	});
        });
        
        // 取消全选
        $("#btn_unCheckAll_addCity").click(function(){
        	$("#cities_Ul input[type='checkbox']").each(function(){
        		$(this).removeAttr("checked");
        	});
        });
        
        // =======添加周边城市相关处理===========>>>>>>>
        // 从添加周边城市返回
        $("#btn_rtn_addAdjoinCity").click(function(){
        	$("#add_adjoin_cities").hide();
        });
        
        // 全选
        $("#btn_checkAll_addAdjoinCity").click(function(){
        	$("#adjoin_cities_Ul input[type='checkbox']").each(function(){
        		$(this).attr("checked", true);
        	});
        });
        
        // 取消全选
        $("#btn_unCheckAll_addAdjoinCity").click(function(){
        	$("#adjoin_cities_Ul input[type='checkbox']").each(function(){
        		$(this).removeAttr("checked");
        	});
        });
        
        // 保存要添加的周边城市
        $("#btn_add_addAdjoinCity").click(function(){
        	var idList = "";
        	$("input[type='checkbox']:checked").each(function(){
        		if (idList == "") {
        			idList = $(this).attr("data-city-id");
        		} else {
        			idList += "," + $(this).attr("data-city-id");
        		}
        		
        	});
        	var url = "__URL__/saveAdjoinCities";
        	$("#idList_add").val(idList);
        	if($.trim(idList) == ""){
        		alert("请先选择要添加的周边城市");
        		return false;
        	}
        	$("#add_djoin_cities_form").attr("action", url);
        	$("#add_djoin_cities_form").submit();
        });
       // =======添加周边城市相关处理===========<<<<<<<<
        
        // =======删除周边城市相关处理===========>>>>>>>
        // 从添加周边城市返回
        $("#btn_rtn_removeAdjoinCity").click(function(){
        	$("#remove_adjoin_cities").hide();
        });
        
        // 全选
        $("#btn_checkAll_removeAdjoinCity").click(function(){
        	$("#adjoin_cities_Ul_remove input[type='checkbox']").each(function(){
        		$(this).attr("checked", true);
        	});
        });
        
        // 取消全选
        $("#btn_unCheckAll_removeAdjoinCity").click(function(){
        	$("#adjoin_cities_Ul_remove input[type='checkbox']").each(function(){
        		$(this).removeAttr("checked");
        	});
        });
        
        // 保存要添加的周边城市
        $("#btn_add_removeAdjoinCity").click(function(){
        	var idList = "";
        	$("input[type='checkbox']:checked").each(function(){
        		if (idList == "") {
        			idList = $(this).attr("data-city-id");
        		} else {
        			idList += "," + $(this).attr("data-city-id");
        		}
        		
        	});
        	var url = "__URL__/removeAdjoinCities";
        	$("#idList_remove").val(idList);
        	if($.trim(idList) == ""){
        		alert("请先选择要添加的周边城市");
        		return false;
        	}
        	$("#remove_djoin_cities_form").attr("action", url);
        	$("#remove_djoin_cities_form").submit();
        });
        // =======删除周边城市相关处理===========<<<<<<<<
      });
      
   	  // 添加城市
      function addCities(cities) {
      	$("#cities_Ul").html("");
          var appendHtml = "<li>";
          var loopIndex = 1;
          for(var index = 0; index < cities.length; index++) {
          	appendHtml += '<span><input type="checkbox"><label>' + cities[index] + '</label></span>';
          	if (loopIndex == 3
          			|| index == cities.length - 1) {
          		$("#cities_Ul").append(appendHtml + "</li>");
          		loopIndex = 1;
          		appendHtml = "<li>";
          	} else {
          		loopIndex++;
          	}
          }
          $("#add_cities").css("display", "block");
      }
   	  
   	  
   	  
      // 添加周边城市
      function adjoinCitiesForShow(cities, type) {
    	  if(type == "add"){
    		  $("#adjoin_cities_Ul").html("");
    	  } else if(type == "remove"){
    		  $("#adjoin_cities_Ul_remove").html("");
    	  }
      	
          var appendHtml = "<li>";
          var loopIndex = 1;
          for(var index = 0; index < cities.length; index++) {
          	appendHtml += '<span><input type="checkbox" data-city-id = "' + cities[index].id + '"><label>' + cities[index].name + '</label></span>';
          	if (loopIndex == 3
          			|| index == cities.length - 1) {
          		 if(type == "add"){
	          			$("#adjoin_cities_Ul").append(appendHtml + "</li>");
	          	  } else if(type == "remove"){
	          		  $("#adjoin_cities_Ul_remove").append(appendHtml + "</li>");
	          	  }
          		
          		loopIndex = 1;
          		appendHtml = "<li>";
          	} else {
          		loopIndex++;
          	}
          }
          if(type == "add"){
        	  $("#add_adjoin_cities").css("display", "block");
    	  } else if(type == "remove"){
    		  $("#remove_adjoin_cities").css("display", "block");
    	  }
          
      }
   	  
   	  // 添加周边城市
   	  function addAdjoinCities(cityId){
   		  $("#cityId_add").val(cityId);
   		  $.ajax({
   			 url:"__URL__/getOtherCity",
   			 type:"POST",
   			 async:true,
   			 data:"cityId=" + cityId,
   			 dataType:"json",
   			 success:function(respData){
   				 if(respData != null && respData.length > 0){
   					adjoinCitiesForShow(respData, "add");
   				 }
   			 },
   			 error:function(){
   				 
   			 }
   		  });
   	  }
   	  
      // 删除周边城市
   	  function removeAdjoinCities(cityId){
   		  $("#cityId_remove").val(cityId);
   		  $.ajax({
   			 url:"__URL__/getAdjoinCity",
   			 type:"POST",
   			 async:true,
   			 data:"cityId=" + cityId,
   			 dataType:"json",
   			 success:function(respData){
   				 if(respData != null && respData.length > 0){
   					adjoinCitiesForShow(respData, "remove");
   				 }
   			 },
   			 error:function(){
   				 
   			 }
   		  });
   	  }
   </script>
   <title>景点管理</title>
 </head>
 <body>
  <div class="container">
     <div id="search_bar" class="mt10">
       <div class="box">
          <div class="box_border">
            <div class="box_top"><b class="pl5">城市管理</b></div>
          </div>
        </div>
    </div>
    <div class="box_bottom pb5 pt5 pr10" style="border:1px solid #dadada;border-bottom:0;margin-top:10px;">
         <div class="search_bar_btn" style="margin-left:2px;">
            <form method="post" id="operationForm">
            	 <input type="hidden" id="del_id" name="idList"> 
             <input type="button" id="btn_add" class="btn btn82 btn_add"  value="添加"> 
             <input type="button" id="btn_checkAll" class="btn btn82 btn_checked" value="全选"> 
  				 <input type="button" id="btn_unCheckAll" class="btn btn82 btn_nochecked" value="取消">
   			 <input type="button" id="btn_del" class="btn btn82 btn_del" value="删除">
            </form>
         </div>
    </div>
     <div id="table" class="mt10">
        <div class="box span10 oh">
              <table  border="0" cellpadding="0" cellspacing="0" class="list_table">
              <tr>
                   <th width="5%">#</th>
                   <th width="15%">城市编号</th>
                   <th>城市名称</th>
                  <!--  <th>周边城市</th>
                   <th width="10%">周边城市管理</th> -->
                </tr>
                <foreach name="cities" item="city">
                <tr class="tr">
                   <td class="td_center">
                   		<input type="checkbox" name="del_checkbox">
                   		<input type="hidden" value="{$city.id}">
                   </td>
                   <td class="td_center">{$city.id}</td>
                   <td class="td_center">{$city.name}</td>
                   <!-- <td class="td_center">{$city.adjoinCities}</td>
                   <td class="td_center">
                   		<a href="javascript:addAdjoinCities({$city.id})" style="text-decoration:underline;">添加</a>
                   		<a href="javascript:removeAdjoinCities({$city.id})" style="text-decoration:underline;">删除</a>
                   </td> -->
                 </tr>
                 </foreach>
              </table>
        </div>
        <div class="pages"> {$page}</div>
     </div>
   </div> 
   <div style="display:none;" id="add_cities" class="add_cities">
	   <form method="post" id="add_cities_form" class="add_cities_form">
	     <input type="hidden" name="cityName">
	     <div style="height:400px;overflow-y:auto;overflow-x:hidden">
	     <ul id="cities_Ul">
	    </ul>
	    </div>
	    <input type="button" id="btn_add_addCity" class="btn btn82 btn_save2"  value="保存"> 
        <input type="button" id="btn_checkAll_addCity" class="btn btn82 btn_checked" value="全选"> 
	 	<input type="button" id="btn_unCheckAll_addCity" class="btn btn82 btn_nochecked" value="取消">
	 	<input type="button" id="btn_rtn_addCity" class="btn btn82 btn_res" value="返回">
	   </form>
	</div>
	<div style="display:none;" id="add_adjoin_cities" class="add_cities">
	   <form method="post" id="add_djoin_cities_form" class="add_cities_form">
	     <input type="hidden" name="idList" id="idList_add">
	     <input type="hidden" name="cityId" id="cityId_add">
	     <div style="height:400px;overflow-y:auto;overflow-x:hidden">
	     <ul id="adjoin_cities_Ul">
	    </ul>
	    </div>
	    <input type="button" id="btn_add_addAdjoinCity" class="btn btn82 btn_save2"  value="保存"> 
        <input type="button" id="btn_checkAll_addAdjoinCity" class="btn btn82 btn_checked" value="全选"> 
	 	<input type="button" id="btn_unCheckAll_addAdjoinCity" class="btn btn82 btn_nochecked" value="取消">
	 	<input type="button" id="btn_rtn_addAdjoinCity" class="btn btn82 btn_res" value="返回">
	   </form>
	</div>
	<div style="display:none;" id="remove_adjoin_cities" class="add_cities">
	   <form method="post" id="remove_djoin_cities_form" class="add_cities_form">
	     <input type="hidden" name="idList" id="idList_remove">
	     <input type="hidden" name="cityId" id="cityId_remove">
	     <div style="height:400px;overflow-y:auto;overflow-x:hidden">
	     <ul id="adjoin_cities_Ul_remove">
	    </ul>
	    </div>
	    <input type="button" id="btn_add_removeAdjoinCity" class="btn btn82 btn_save2"  value="保存"> 
        <input type="button" id="btn_checkAll_removeAdjoinCity" class="btn btn82 btn_checked" value="全选"> 
	 	<input type="button" id="btn_unCheckAll_removeAdjoinCity" class="btn btn82 btn_nochecked" value="取消">
	 	<input type="button" id="btn_rtn_removeAdjoinCity" class="btn btn82 btn_res" value="返回">
	   </form>
	</div>
 </body>
 </html>
  